import datetime
from pathlib import Path
from typing import Union
from loguru import logger
import collections

from .utils import get_project_path, time_format, create_folders


class Log:
    def __init__(self, save_path: Union[str, Path, None] = None, buffer_size: int = 1024):
        if save_path is None:
            log_root_dir = get_project_path() / 'Log'
            create_folders(log_root_dir)
            save_path = log_root_dir / f'{self.__class__.__name__}_{time_format(datetime.datetime.now())}.log'
        self.save_path = Path(save_path)
        self.buffer_size = buffer_size
        self.log_deque = collections.deque(maxlen=buffer_size)
        self.kill_catch_thread = False

    def start_catch(self):
        self.kill_catch_thread = False

    def stop_catch(self):
        self.kill_catch_thread = True


if __name__ == '__main__':
    logger.add('run.log')
    Log()
